Skip to content

fix(vercel): prevent caching missing public assets (nitrojs/nitro#4474) - #42

Merged
pi0 merged 1 commit into
nitrojs:mainfrom
danielroe:backport-public-assets-404
Nov 12, 2026
Merged

pi0 merged 1 commit into
nitrojs:mainfrom
danielroe:backport-public-assets-404

Conversation

@danielroe

@danielroe danielroe commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

this comes out of some cost-optimisation work on npmx, which serves a few hundred build-time JSON files from a non-fallthrough publicAssets base on Vercel.

a request under that base for a file that doesn't exist isn't stopped at the CDN

this is an issue already fixed in nitro v3 in nitrojs/nitro#4474, so this backports some of that PR to v2.

I've left out the maxAge part, as that would change public types.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Co-authored-by: Ryan Conceicao <ryoid@users.noreply.github.com>
@danielroe
danielroe requested a review from pi0 as a code owner November 12, 2026 18:58
@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@danielroe is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Vercel preset now generates route patterns for eligible public asset directories. It adds immutable-cache rules before filesystem handling and 404/no-store rules after filesystem handling.

Changes: Vercel public-asset routes

Layer / File(s) Summary
Generate and apply public-asset routes
src/presets/vercel/utils.ts, test/presets/vercel.test.ts, test/unit/vercel-public-asset-routes.test.ts
getPublicAssetRoutes returns escaped, base-prefixed patterns for non-fallthrough assets whose base is not /. The Vercel config uses these patterns for immutable-cache rules before filesystem handling and 404/no-store rules after it. Tests cover route generation, exclusions, pattern matching, and rule ordering.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Merge Risk: Minimal · up to 8b288

This change adds 404 and no-store rules for missing files under non-fallthrough public asset directories on Vercel, so missing assets are no longer cached. No merge-blocking risk was identified in the reviewed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the conventional commits format (fix(vercel): ...). It names the scope (vercel) and states the main change: preventing caching of missing public assets. The changeset adds getPublicAsse…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description explains the change. It says the work comes from cost-optimisation on npmx, which serves build-time JSON files from a non-fallthrough publicAssets base on Vercel. It states that reques…
Full details: Title check

Explanation

The title uses the conventional commits format (fix(vercel): ...). It names the scope (vercel) and states the main change: preventing caching of missing public assets. The changeset adds getPublicAssetRoutes and no-store 404 routes for missing files under public asset directories, which matches the title.

Full details: Description check

Explanation

The description explains the change. It says the work comes from cost-optimisation on npmx, which serves build-time JSON files from a non-fallthrough publicAssets base on Vercel. It states that requests for missing files under that base are not stopped at the CDN. It says the fix backports part of nitrojs/nitro#4474 to v2 and omits the maxAge part to avoid changing public types. This matches the changeset, which adds getPublicAssetRoutes and 404/no-store routes for Vercel public asset directories.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 85fe043e-78f8-4725-8662-dc33f87a3b5b
Commits

Reviewing files that changed from the base of the PR and between 96eb8c7 and 8b2883b.

Files selected for processing: 3

  • src/presets/vercel/utils.ts
  • test/presets/vercel.test.ts
  • test/unit/vercel-public-asset-routes.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@pi0
pi0 merged commit 7548d7f into nitrojs:main Nov 12, 2026
13 of 14 checks passed
@danielroe
danielroe deleted the backport-public-assets-404 branch November 12, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants